package com.cn.scenario.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.cn.scenario.entity.AppUser;
import com.cn.scenario.service.CurriculumService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author Boolean
 * @Date 2022/12/28 22:23
 * @Version 1.0
 */
@RestController
@RequestMapping("/curriculum")
public class CurriculumController {

    @Resource
    CurriculumService curriculumService;


    /**
     * @description: 选课
     * @author: 任秀兴
     * @date: 2022/12/28 23:37
     * @param: [id]
     * @return: java.lang.Boolean
     **/
    @GetMapping("/{id}")
    public Boolean CourseSelection(@PathVariable int id) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        for (int i = 0; i < 1000; i++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName() + "正在执行任务");
                    //System.out.println(curriculumService.CourseSelection(id,Thread.currentThread().getName()));

                    System.out.println(curriculumService.CourseSelectionLock(id,Thread.currentThread().getName()));
                }
            });
        }
        return true;
    }



}
